﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.Core.Model;

namespace EzDesk.Core.ServiceImpl.Filters
{
    public static class UserFilter
    {
        public static UserProfile ByUserName(this IQueryable<UserProfile> query, string userName)
        {
            return query.Where(p => p.UserCode == userName).FirstOrDefault();
        }

        public static UserProfile ByUserId(this IQueryable<UserProfile> query, Guid userId)
        {
            return query.Where(p => p.Id == userId).FirstOrDefault();
        }


        
        public static SimpleUser ByUserId(this IQueryable<SimpleUser> query, Guid userId)
        {
            return query.Where(p => p.Id == userId).FirstOrDefault();
        }

        public static SimpleUser ByUserName(this IQueryable<SimpleUser> query, string userName)
        {
            return query.Where(p => p.UserName == userName).FirstOrDefault();
        }



        public static IQueryable<SimpleUser> InDept(this IQueryable<UserProfile> query, Guid deptId)
        {
            return query.Where(p => p.DeptId == deptId)
                .Select(p => new SimpleUser { Id = p.Id, UserName = p.UserCode, Name = p.Name });
        }

        public static IQueryable<SimpleUser> InPosition(this IQueryable<UserProfile> query, Guid posId)
        {
            return query.Where(p => p.PositionId == posId)
                .Select(p => new SimpleUser { Id = p.Id, UserName = p.UserCode, Name = p.Name });
        }

    }
}
